<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">{$space.name}</h3>
        <a href="{:url('poster/posterlist',['id'=>$space['id']])}" title="返回广告列表"><i class="fa fa-fw fa-reply-all"></i></a>
    </div>
    <!-- /.box-header -->
    <!-- form start -->
    <form class="form-horizontal" action="{:url('poster/editposter',['spaceid'=>$space['id']])}" method="post">
        <input type='hidden' name='spaceid' value="{$space.id}" />
        <input type='hidden' name='id' value='{$info?$info["id"]:""}' />
        <div class="box-body">
            <div class="form-group">
                <label for="posterName" class="col-sm-2 control-label">广告标题：</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="posterName" name="name" value='{$info?$info["name"]:""}' placeholder="广告标题" required="">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">所属版位：</label>

                <div class="col-sm-10">
                    <label class="control-label">{$space.name}</label>
                </div>
            </div>
            <div class="form-group">
                <label for="posterType" class="col-sm-2 control-label">广告类型：</label>
                <div class="col-sm-2">
                    <select class="form-control" name="type" id="posterType">
                        {foreach $posterType as $key=>$value}
                        <option value="{$key}">{$value}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="subtitle" class="col-sm-2 control-label">副标题：</label>

                <div class="col-sm-6">
                    <input type="text" class="form-control" id="subtitle" name="subtitle" value='{$info?$info["subtitle"]:""}' placeholder="副标题">
                </div>
            </div>
            <div class="form-group">
                <label for="description" class="col-sm-2 control-label">广告描述：</label>

                <div class="col-sm-6">
                    <textarea class="form-control" rows="3" id="description" placeholder="广告描述 ..." name="description">{$info?$info["description"]:""}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="startdate" class="col-sm-2 control-label">开始时间：</label>

                <div class="col-sm-2">
                    <input type="text" class="form-control datepicker" name='startdate' {if !empty($info) && $info['startdate']}value="{:date('Y-m-d',$info['startdate'])}"{/if}  data-date-start-date="0d">
                </div>
            </div>
            <div class="form-group">
                <label for="enddate" class="col-sm-2 control-label">结束时间：</label>

                <div class="col-sm-2">
                    <input type="text" class="form-control datepicker" name='enddate' {if !empty($info) && $info['enddate']}value="{:date('Y-m-d',$info['enddate'])}"{/if} data-date-start-date="0d">
                </div>
            </div>
            <div class="form-group">
                <label for="list_order" class="col-sm-2 control-label">排序值：</label>

                <div class="col-sm-2">
                    <input type="number" class="form-control" id="list_order" name="list_order" value='{$info?$info["list_order"]:""}' placeholder="排序值">
                </div>
            </div>
            <div class="form-group">
                <label for="spaceStatus" class="col-sm-2 control-label">是否启用：</label>

                <div class="col-sm-2">
                    <select class="form-control" id="spaceStatus" name="status">
                        {foreach $posterStatus as $key=>$value}
                        <option value="{$key}" {if !empty($info) && $info['status'] == $key}selected{/if}>{$value}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="link" class="col-sm-2 control-label">广告链接：</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="link" name="link" value='{$info?$info["link"]:""}' placeholder="广告链接">
                </div>
            </div>
            <div class="form-group">
                <label for="link_title" class="col-sm-2 control-label">链接标题：</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="link_title" name="link_title" value='{$info?$info["link_title"]:""}' placeholder="链接标题,此值为空显示广告标题">
                </div>
            </div>
            <div class="form-group">
                <label for="img_path" class="col-sm-2 control-label">图片设置：</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control" id="img_path" name="img_path" value='{$info?$info["img_path"]:""}' placeholder="图片地址">
                </div>
                <div class="col-sm-3">
                    <input type="file" class="form-control btn btn-file" onchange="upPoserImg(this)"/>
                </div>
                <div class="col-sm-3">
                    <img src='{$info?$info["img_path"]:""}' alt='{$info?$info["name"]:""}' id="posterImg" class="online" width="90%"/>
                </div>
            </div>
            <hr/>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-6">
                    <button type="reset" class="btn btn-default">重置</button>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <button type="submit" class="btn btn-info">提交</button>
                </div>
                <div class="col-sm-4">

                </div>
            </div>
        </div>
    </form>
</div>
<script type='text/javascript'>
    $(function () {
        $('.datepicker').datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true
        });
    });

    /**
     * 上传图片
     * @param {type} fileInput
     * @returns {undefined}
     */
    function upPoserImg(fileInput) {
        var file = $(fileInput)[0].files[0];
        //console.log($(fileInput));
        ajaxFile(file, function (response) {
            console.log(response);
            if (response.code == 1) {
                $('#img_path').val(response.msg);
                $('#posterImg').attr('src', response.msg);
            } else {
                toast('图片上传失败', response.msg, 2000);
            }
        });
    }
</script>
